package com.warm.mini.wework.config;

import com.warm.mini.wework.constant.WeworkModelEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description tanzsay wework config
 * @Author warmchuang
 * @Date 2022/2/7 16:46
 */
@Configuration
public class TanzsayConfig {
    public static final String NAME = "炭治说";
    public static final String RESOURCE = "tanzsay";
    public static final String CORP_ID = "wwed8a8fdc9b2d8385";

    @Bean("tanzsayContact")
    @Primary
    public WeworkConfigProperties contactConfig(){
        WeworkConfigProperties config = new WeworkConfigProperties();
        init(config);
        config.setModel(WeworkModelEnum.CONTACT.getValue());

        config.setToken("RWNJwoqhpMemYBiqrS1fkCOzFW55");
        config.setEncodingAESKey("6h6BKYVf7GscKQBd5jVEb213JYfgVycQMXqlqXtsPEC");
        config.setCorpSecret("rk4OFW95rAIYGA2UP16S54m-0GSqUCbxJ_Vl_xTIFPw");
        return config;
    }

    @Bean("tanzsayExternalContact")
    @Primary
    public WeworkConfigProperties externalContactConfig(){
        WeworkConfigProperties config = new WeworkConfigProperties();
        init(config);
        config.setModel(WeworkModelEnum.CONTACT.getValue());

        config.setToken("zMaxOWaz0rSSNSlJQmiyFTrzV");
        config.setEncodingAESKey("7Guku2nMyEGTMyCtvICLiSqSoZdPDTXDX6BJEAEFF5Y");
        config.setCorpSecret("ZE6f7EiTiilziti2w7ZTMTKVgeBCKqExa_29u-zZ990");
        return config;
    }

    @Bean("tanzsayBuildApplication")
    @Primary
    public Map<String, WeworkConfigProperties> buildApplicationConfig(){
        Map<String, WeworkConfigProperties> map = new ConcurrentHashMap<>();
        /** 自建应用 1 */
        WeworkConfigProperties config1 = setBuildApplicationConfig("5Ew_8C3TKjXBxqzukFrLrkcR03a1r83_VZ1K_cxNf3E", "1000002");
        map.put(config1.getAgentId(), config1);

        /** 自建应用 1 */
        WeworkConfigProperties config2 = setBuildApplicationConfig("S6LRnQtEwBR69M0B3GmlbH1aNzXJbFs_98kHZKtFljc", "1000003");
        map.put(config2.getAgentId(), config2);
        map.put(config2.getAgentId(), config2);

        return map;
    }

    private WeworkConfigProperties setBuildApplicationConfig(String corpSecret, String agentId){
        WeworkConfigProperties config = new WeworkConfigProperties();
        init(config);
        config.setModel(WeworkModelEnum.BUILD_APPLICATION.getValue());
        config.setCorpSecret(corpSecret);
        config.setAgentId(agentId);
        return config;
    }

    private void init(WeworkConfigProperties config){
        config.setResource(RESOURCE);
        config.setCorpId(CORP_ID);
    }
}
